package com.lgc.javathread.signalTest.cyclicBarrierTest;

import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierTest2 {
    public static void main(String[] args) {
        final int N = 4;
        //参数barrierAction为当这些线程都达到barrier状态时会执行的内容。
        CyclicBarrier barrier = new CyclicBarrier(N, new Runnable() {
            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                System.out.println(name + "barrier Runnable");
            }
        });
        /*CyclicBarrier barrier = new CyclicBarrier(N,new Thread() {
            @Override
            public void run() {
                String name=Thread.currentThread().getName();
                System.out.println(name +"barrier Runnable");
            }
        });*/

        for (int i = 0; i < N; i++) {
            new Thread(new Writer(barrier, i + 1)).start();
        }
    }
}
